package com.kc.data.scenic.controller;

import com.kc.data.common.core.AjaxResult;
import com.kc.data.common.core.controller.BaseController;
import com.kc.data.common.domain.model.BizGoodsSku;
import com.kc.data.common.domain.model.BizGoodsSkuCategory;
import com.kc.data.common.enums.GoodsSkuCategoryTypeEnum;
import com.kc.data.common.page.TableDataInfo;
import com.kc.data.common.service.IBizGoodsSkuCategoryService;
import com.kc.data.common.service.IBizGoodsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName BizGoodsSkuController
 * @Description 商品规格管理
 * @Author wangdongliang
 * @Date 2021/6/16 10:19
 */
@RestController
@RequestMapping("/business/goodsSku")
public class BizGoodsSkuController extends BaseController {
    @Autowired
    private IBizGoodsSkuService goodsSkuService;
    @Resource
    private IBizGoodsSkuCategoryService goodsSkuCategoryService;

    /**
     * 商品规格列表
     * @param bizGoodsSku
     * @return
     */
    @PostMapping("/getList")
    public TableDataInfo getList(@RequestBody BizGoodsSku bizGoodsSku){
        startPage();
        return getDataTable(goodsSkuService.getList(bizGoodsSku));
    }

    /**
     * 获取类别列表
     * @return
     */
    @GetMapping("/getSkuCategory")
    public TableDataInfo getSkuCategory(){
        startPage();
        BizGoodsSkuCategory bizGoodsSkuCategory = new BizGoodsSkuCategory();
        return getDataTable(goodsSkuCategoryService.getList(bizGoodsSkuCategory));
    }

    /**
     * 类别新增
     * @param bizGoodsSkuCategory
     * @return
     */
    @PostMapping("/addSkuCategory")
    public AjaxResult addSkuCategory(@Validated @RequestBody BizGoodsSkuCategory bizGoodsSkuCategory) {
        bizGoodsSkuCategory.setIsDeleted(0);
        if(bizGoodsSkuCategory == null){
            bizGoodsSkuCategory.setTenantType(GoodsSkuCategoryTypeEnum.PLATFORM.getValue());
        }
        BizGoodsSkuCategory goodsSkuCategory = new BizGoodsSkuCategory();
        goodsSkuCategory.setName(bizGoodsSkuCategory.getName());
        goodsSkuCategory.setIsDeleted(0);
        goodsSkuCategory.setTenantType(bizGoodsSkuCategory.getTenantType());
        if(null != goodsSkuCategoryService.getInfo(goodsSkuCategory)){
            return AjaxResult.error("类别名称已存在");
        }
        return AjaxResult.success(goodsSkuCategoryService.add(bizGoodsSkuCategory));
    }



}
